function foo(a, b, c) {
    // console.log(a, b, c)
    this.name = a
    this.age = b
    this.angle = c
    // console.log('this', this.name, ...arguments)
    return 'haha'
}

foo.prototype.show = function() {
    console.log('my name is ' + this.name)
}

const name = 'window'
const obj = {name: 'kaho'}

Function.prototype.myCall = function(context = window, ...args) {
    if(typeof this !== 'function') throw new Error('error')
    
    const fn = Symbol('fn')
    context[fn] = this
    const result = context[fn](...args)
    delete context.fn

    return result
}

Function.prototype.myApply = function(context, args) {
    if(typeof this !== 'function') throw new Error('error')

    const fn = Symbol('fn')
    context[fn] = this
    const result = context[fn](...args)
    delete context.fn

    return result
}

Function.prototype.myBind = function(context, ...args) {
    if(typeof this !== 'function') throw new Error('error')

    const fn = this
    const fnn = function() {
        return fn.apply(this instanceof fnn ? this : context, [...args, ...arguments])
    }
    fnn.prototype = Object.create(fn.prototype)
    return fnn
}

// const Foo = foo.myBind(obj)
// // console.log(Foo(1,2,3))
// // console.log(Foo())
// const fobj = new Foo(1,2,3)

// // console.log(fobj.show())

// let test = foo.bind(obj)

// const tester = new test()

// console.log('tester', tester.constructor)

